//
//  FBNetWorkUrlTool.m
//  Fireball
//
//  Created by 俞渊华 on 2017/12/2.
//  Copyright © 2017年 俞渊华. All rights reserved.
//

#import "FBNetWorkUrlTool.h"



#import "NSObject+Extension.h"

#import "NSString+AES.h"

@implementation FBNetWorkUrlTool


+(NSString *)urlString:(NSString *)url parameters:(NSDictionary *)parameters{
    
    ///字典转json
    parameters = [self parameters:parameters];
    NSString *encryptStr = parameters.mj_JSONString;
    ///json加密
    encryptStr = [encryptStr aci_encryptWithAES];
    //特殊符号处理
    encryptStr = [encryptStr stringByReplacingOccurrencesOfString:@"+" withString:@"$__2B$"];
    encryptStr = [encryptStr stringByReplacingOccurrencesOfString:@"/" withString:@"$__2F$"];
    encryptStr = [encryptStr stringByReplacingOccurrencesOfString:@"=" withString:@"$_2C$"];
    encryptStr = [encryptStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    //加密之后拼接url
    NSString * urlStr = [NSString stringWithFormat:@"https://wcf.ihuoqiu.com/%@?data=%@",url,encryptStr];
    
    return urlStr;
}

+(NSMutableDictionary *)parameters:(NSDictionary *)parameters{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];

    if (parameters) {
        [dict addEntriesFromDictionary:parameters];
    }
//    /// <summary>
//    /// 设备唯一标识
//    /// </summary>
//    public string PhoneUniqueId { get; set; }
//    /// <summary>
//    /// 用户唯一标识
//    /// </summary>
//    public string LoginKey { get; set; }
//    /// <summary>
//    /// 当前版本号
//    /// </summary>
//    public string Version { get; set; }


    [dict setObject:[XMTool shared].deviceId forKey:@"PhoneUniqueId"];//设备标识
    if ([UserAccountTool account].LoginKey) {
        [dict setObject:[UserAccountTool account].LoginKey forKey:@"LoginKey"];
    }else{
        [dict setObject:@"a6f32394-8e1e-4151-a023-9eb0daac674a" forKey:@"LoginKey"];
    }
    [dict setObject:@"v1.0" forKey:@"Version"];//API版本
    
    
//    NSLog(@"LoginKey == %@",[UserAccountTool account].LoginKey);
//    [dict setObject:@"a6f32394-8e1e-4151-a023-9eb0daac674a" forKey:@"LoginKey"];//登录key

    
    return dict;
}




@end
